#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e6;
int vis[500010],dis[4010][4010],ans,mnx,mny,mxx,mxy,n,qx[500010],qhx[500010];
int hx[500010],hhx[500010],qy[500010],hy[500010],qhy[500010],hhy[500010];
unordered_map<long long,int>mp;
struct node{
	int x,y;
}a[500010];
queue<node>q;
void dfs(int x,int y,int id){
	q.push({x,y});
	for(int i=1;i<=n;i++)vis[i]=0;
	vis[id]=1,vis[0]=1;
	while(!q.empty()){
		int x=q.front().x,y=q.front().y;
		q.pop();
//		cout<<x<<" "<<y<<" "<<mp[x*inf+y]<<" "<<dis[id][mp[x*inf+y]]<<"\n";
		if(dis[id][mp[(x-1)*inf+y]]>dis[id][mp[x*inf+y]]+1){
			dis[id][mp[(x-1)*inf+y]]=dis[id][mp[x*inf+y]]+1;
			if(vis[mp[(x-1)*inf+y]]==0){
				vis[mp[(x-1)*inf+y]]=1;
				q.push({x-1,y});
			}
		}
		if(dis[id][mp[(x+1)*inf+y]]>dis[id][mp[x*inf+y]]+1){
			dis[id][mp[(x+1)*inf+y]]=dis[id][mp[x*inf+y]]+1;
			if(vis[mp[(x+1)*inf+y]]==0){
				vis[mp[(x+1)*inf+y]]=1;
				q.push({x+1,y});
			}
		}
		if(dis[id][mp[(x)*inf+y+1]]>dis[id][mp[x*inf+y]]+1){
			dis[id][mp[(x)*inf+y+1]]=dis[id][mp[x*inf+y]]+1;
			if(vis[mp[(x)*inf+y+1]]==0){
				vis[mp[(x)*inf+y+1]]=1;
				q.push({x,y+1});
			}
		}
		if(dis[id][mp[(x)*inf+y-1]]>dis[id][mp[x*inf+y]]+1){
			dis[id][mp[(x)*inf+y-1]]=dis[id][mp[x*inf+y]]+1;
			if(vis[mp[(x)*inf+y-1]]==0){
				vis[mp[(x)*inf+y-1]]=1;
				q.push({x,y-1});
			}
		}
	}
}
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("game.in","r",stdin);
	freopen("game.out","w",stdout);
	cin>>n,mnx=inf*inf,mny=inf*inf;
	for(int i=1;i<=n;i++)cin>>a[i].x>>a[i].y,mnx=min(mnx,a[i].x),mny=min(mny,a[i].y);
	for(int i=1;i<=n;i++)a[i].x-=mnx,a[i].y-=mny,mxx=max(mxx,a[i].x),mxy=max(mxy,a[i].y);
	if(n<=0){
		for(int i=1;i<=n;i++)mp[a[i].x*inf+a[i].y]=i;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				dis[i][j]=inf; 
			}
			dis[i][i]=0;
		}
		for(int i=1;i<=n;i++){
			dfs(a[i].x,a[i].y,i);
			for(int j=1;j<=n;j++){
				ans+=dis[i][j];
//				cout<<dis[i][j]<<" ";
			}
//			cout<<"\n";
		}
		cout<<ans/2;
	}
	else if((mxx+1)*(mxy+1)==n){
		for(int i=1;i<=n;i++){
			int num=a[i].x,sum=0;
			sum+=num*(num+1)/2;
//			cout<<num<<" "<<sum<<"\n";
			num=mxx-a[i].x;
			sum+=num*(num+1)/2;
//			cout<<num<<" "<<sum<<"\n";
			ans+=(mxy+1)*sum;
//			cout<<ans<<" "<<mxy+1<<" "<<sum<<"\n";
			sum=0;
			num=a[i].y;
			sum+=num*(num+1)/2;
//			cout<<num<<" "<<sum<<"\n";
			num=mxy-a[i].y;
			sum+=num*(num+1)/2;
//			cout<<num<<" "<<sum<<"\n";
			ans+=(mxx+1)*sum;
//			cout<<ans<<" "<<mxx+1<<" "<<sum<<"\n";
		}
		cout<<ans/2;
	}
	else{
		for(int i=1;i<=n;i++){
			qx[a[i].x+1]++;
			hx[a[i].x+1]++;
			qhx[a[i].x+1]+=a[i].x;
			hhx[a[i].x+1]+=mxx-a[i].x;
			qy[a[i].y+1]++;
			hy[a[i].y+1]++;
			qhy[a[i].y+1]+=a[i].y;
			hhy[a[i].y+1]+=mxy-a[i].y;
		}
		for(int i=1;i<=mxx+1;i++)qx[i]+=qx[i-1],qhx[i]+=qhx[i-1];
		for(int i=1;i<=mxy+1;i++)qy[i]+=qy[i-1],qhy[i]+=qhy[i-1];
		for(int i=mxx;i>=1;i--)hx[i]+=hx[i+1],hhx[i]+=hhx[i+1];
		for(int i=mxy;i>=1;i--)hy[i]+=hy[i+1],hhy[i]+=hhy[i+1];
//		for(int i=1;i<=mxx+1;i++)cout<<hhx[i]<<" ";
//		cout<<"\n";
		for(int i=1;i<=n;i++){
			int sum=hhx[1]-hhx[a[i].x+2]-qx[a[i].x+1]*(mxx-a[i].x);
//			cout<<hhx[1]-hhx[a[i].x+2]<<" "<<qx[a[i].x+1]<<" "<<(mxx-a[i].x)<<"\n";
			sum+=qhx[mxx+1]-qhx[a[i].x]-hx[a[i].x+1]*(a[i].x);
//			cout<<
			sum+=hhy[1]-hhy[a[i].y+2]-qy[a[i].y+1]*(mxy-a[i].y);
			sum+=qhy[mxy+1]-qhy[a[i].y]-hy[a[i].y+1]*(a[i].y);
			ans+=sum;
//			cout<<ans<<"\n";
		}
		cout<<ans/2;
	}
	return 0;
}
/*
4
1 1
1 2
2 2 
2 3

181894422062600
 61108104775900

*/
